{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>number</th>\n",
       "      <th>target_num</th>\n",
       "      <th>sum</th>\n",
       "      <th>total_saling</th>\n",
       "      <th>date</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>星期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>8293</td>\n",
       "      <td>0 9 9 9 2</td>\n",
       "      <td>29</td>\n",
       "      <td>6,631,522</td>\n",
       "      <td>2008-10-26</td>\n",
       "      <td>戊子</td>\n",
       "      <td>壬戌</td>\n",
       "      <td>己亥</td>\n",
       "      <td>星期日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>8294</td>\n",
       "      <td>0 9 7 3 4</td>\n",
       "      <td>23</td>\n",
       "      <td>6,633,966</td>\n",
       "      <td>2008-10-27</td>\n",
       "      <td>戊子</td>\n",
       "      <td>壬戌</td>\n",
       "      <td>庚子</td>\n",
       "      <td>星期一</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8295</td>\n",
       "      <td>9 4 4 5 6</td>\n",
       "      <td>28</td>\n",
       "      <td>6,529,334</td>\n",
       "      <td>2008-10-28</td>\n",
       "      <td>戊子</td>\n",
       "      <td>壬戌</td>\n",
       "      <td>辛丑</td>\n",
       "      <td>星期二</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8296</td>\n",
       "      <td>7 6 6 8 8</td>\n",
       "      <td>35</td>\n",
       "      <td>6,673,070</td>\n",
       "      <td>2008-10-29</td>\n",
       "      <td>戊子</td>\n",
       "      <td>壬戌</td>\n",
       "      <td>壬寅</td>\n",
       "      <td>星期三</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8297</td>\n",
       "      <td>9 4 1 1 8</td>\n",
       "      <td>23</td>\n",
       "      <td>6,889,586</td>\n",
       "      <td>2008-10-30</td>\n",
       "      <td>戊子</td>\n",
       "      <td>壬戌</td>\n",
       "      <td>癸卯</td>\n",
       "      <td>星期四</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4188</th>\n",
       "      <td>20190</td>\n",
       "      <td>7 3 3 6 3</td>\n",
       "      <td>22</td>\n",
       "      <td>12,570,478</td>\n",
       "      <td>2020-08-27</td>\n",
       "      <td>庚子</td>\n",
       "      <td>甲申</td>\n",
       "      <td>壬寅</td>\n",
       "      <td>星期四</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4189</th>\n",
       "      <td>20191</td>\n",
       "      <td>9 3 6 6 7</td>\n",
       "      <td>31</td>\n",
       "      <td>14,386,980</td>\n",
       "      <td>2020-08-28</td>\n",
       "      <td>庚子</td>\n",
       "      <td>甲申</td>\n",
       "      <td>癸卯</td>\n",
       "      <td>星期五</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4190</th>\n",
       "      <td>20192</td>\n",
       "      <td>8 4 9 8 8</td>\n",
       "      <td>37</td>\n",
       "      <td>11,894,734</td>\n",
       "      <td>2020-08-29</td>\n",
       "      <td>庚子</td>\n",
       "      <td>甲申</td>\n",
       "      <td>甲辰</td>\n",
       "      <td>星期六</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4191</th>\n",
       "      <td>20193</td>\n",
       "      <td>3 0 9 6 6</td>\n",
       "      <td>24</td>\n",
       "      <td>11,943,834</td>\n",
       "      <td>2020-08-30</td>\n",
       "      <td>庚子</td>\n",
       "      <td>甲申</td>\n",
       "      <td>乙巳</td>\n",
       "      <td>星期日</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4192</th>\n",
       "      <td>20194</td>\n",
       "      <td>4 3 6 9 8</td>\n",
       "      <td>30</td>\n",
       "      <td>12,193,554</td>\n",
       "      <td>2020-08-31</td>\n",
       "      <td>庚子</td>\n",
       "      <td>甲申</td>\n",
       "      <td>丙午</td>\n",
       "      <td>星期一</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4193 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      number target_num  sum total_saling        date year month day   星期\n",
       "0       8293  0 9 9 9 2   29    6,631,522  2008-10-26   戊子    壬戌  己亥  星期日\n",
       "1       8294  0 9 7 3 4   23    6,633,966  2008-10-27   戊子    壬戌  庚子  星期一\n",
       "2       8295  9 4 4 5 6   28    6,529,334  2008-10-28   戊子    壬戌  辛丑  星期二\n",
       "3       8296  7 6 6 8 8   35    6,673,070  2008-10-29   戊子    壬戌  壬寅  星期三\n",
       "4       8297  9 4 1 1 8   23    6,889,586  2008-10-30   戊子    壬戌  癸卯  星期四\n",
       "...      ...        ...  ...          ...         ...  ...   ...  ..  ...\n",
       "4188   20190  7 3 3 6 3   22   12,570,478  2020-08-27   庚子    甲申  壬寅  星期四\n",
       "4189   20191  9 3 6 6 7   31   14,386,980  2020-08-28   庚子    甲申  癸卯  星期五\n",
       "4190   20192  8 4 9 8 8   37   11,894,734  2020-08-29   庚子    甲申  甲辰  星期六\n",
       "4191   20193  3 0 9 6 6   24   11,943,834  2020-08-30   庚子    甲申  乙巳  星期日\n",
       "4192   20194  4 3 6 9 8   30   12,193,554  2020-08-31   庚子    甲申  丙午  星期一\n",
       "\n",
       "[4193 rows x 9 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df = pd.read_csv('彩票plus.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据分析\n",
    "\n",
    "**目的**：输出每一日的统计数据，主要为每个数字的数量\n",
    "\n",
    "1. 计算每天各数字出现的频数\n",
    "2. 计算某特定日数字出现的总频数\n",
    "3. 可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "<ipython-input-3-31b3fbab2356>:5: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  df[nnn] = 0\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>target_num</th>\n",
       "      <th>day</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0 9 9 9 2</td>\n",
       "      <td>己亥</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0 9 7 3 4</td>\n",
       "      <td>庚子</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>9 4 4 5 6</td>\n",
       "      <td>辛丑</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>7 6 6 8 8</td>\n",
       "      <td>壬寅</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9 4 1 1 8</td>\n",
       "      <td>癸卯</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4188</th>\n",
       "      <td>7 3 3 6 3</td>\n",
       "      <td>壬寅</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4189</th>\n",
       "      <td>9 3 6 6 7</td>\n",
       "      <td>癸卯</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4190</th>\n",
       "      <td>8 4 9 8 8</td>\n",
       "      <td>甲辰</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4191</th>\n",
       "      <td>3 0 9 6 6</td>\n",
       "      <td>乙巳</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4192</th>\n",
       "      <td>4 3 6 9 8</td>\n",
       "      <td>丙午</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4193 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     target_num day  0  1  2  3  4  5  6  7  8  9\n",
       "0     0 9 9 9 2  己亥  1  0  1  0  0  0  0  0  0  3\n",
       "1     0 9 7 3 4  庚子  1  0  0  1  1  0  0  1  0  1\n",
       "2     9 4 4 5 6  辛丑  0  0  0  0  2  1  1  0  0  1\n",
       "3     7 6 6 8 8  壬寅  0  0  0  0  0  0  2  1  2  0\n",
       "4     9 4 1 1 8  癸卯  0  2  0  0  1  0  0  0  1  1\n",
       "...         ...  .. .. .. .. .. .. .. .. .. .. ..\n",
       "4188  7 3 3 6 3  壬寅  0  0  0  3  0  0  1  1  0  0\n",
       "4189  9 3 6 6 7  癸卯  0  0  0  1  0  0  2  1  0  1\n",
       "4190  8 4 9 8 8  甲辰  0  0  0  0  1  0  0  0  3  1\n",
       "4191  3 0 9 6 6  乙巳  1  0  0  1  0  0  2  0  0  1\n",
       "4192  4 3 6 9 8  丙午  0  0  0  1  1  0  1  0  1  1\n",
       "\n",
       "[4193 rows x 12 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# for s in g\n",
    "df = df[['target_num', 'day']]\n",
    "ii = 0\n",
    "for nnn in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:\n",
    "    df[nnn] = 0\n",
    "for num in df['target_num']:\n",
    "    for i in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:\n",
    "        df.loc[ii, i] = num.count(i)\n",
    "    ii += 1\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['丁丑', '丁亥', '丁卯', '丁巳', '丁未', '丁酉', '丙午', '丙子', '丙寅', '丙戌', '丙申',\n",
       "       '丙辰', '乙丑', '乙亥', '乙卯', '乙巳', '乙未', '乙酉', '壬午', '壬子', '壬寅', '壬戌',\n",
       "       '壬申', '壬辰', '己丑', '己亥', '己卯', '己巳', '己未', '己酉', '庚午', '庚子', '庚寅',\n",
       "       '庚戌', '庚申', '庚辰', '戊午', '戊子', '戊寅', '戊戌', '戊申', '戊辰', '甲午', '甲子',\n",
       "       '甲寅', '甲戌', '甲申', '甲辰', '癸丑', '癸亥', '癸卯', '癸巳', '癸未', '癸酉', '辛丑',\n",
       "       '辛亥', '辛卯', '辛巳', '辛未', '辛酉'], dtype=object)"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby('day').sum().loc['丁丑', :]\n",
    "df.groupby('day').sum().iloc[0, 0]\n",
    "df.groupby('day').sum().index.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\dadi\\\\Python\\\\caipiao\\\\彩票.html'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pyecharts.charts import *\n",
    "tl = Timeline()\n",
    "tl.add_schema()\n",
    "\n",
    "for f in df.groupby('day').sum().index.values:\n",
    "    bar = Bar()\n",
    "    bar.add_xaxis(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])\n",
    "    bar.add_yaxis('出现频数', list(df.groupby('day').sum().loc[f, :]))\n",
    "           \n",
    "    tl.add(bar, f)\n",
    "\n",
    "tl.render_notebook()\n",
    "tl.render('彩票.html')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
